<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向字节编程-cookie</title>
</head>
<body>
    <script>
        // cookie
        // console.log(document.cookie);
        const cookieObj ={};
        const cookieStr ='_ga=GA1.2.2137152850.1618624109; passport_csrf_token_default=02a8f05d2cc1d311c8964c13282b8b5c; passport_csrf_token=02a8f05d2cc1d311c8964c13282b8b5c; ttcid=142c5fc3651445229c7226ac26c5f5e779; MONITOR_WEB_ID=4e9194ad-2a9a-40b3-b5ce-c74f1124364a; _gid=GA1.2.1175243334.1630414450; _tea_utm_cache_2608={%22utm_source%22:%22timeline_1%22%2C%22utm_medium%22:%22banner%22%2C%22utm_campaign%22:%22zhongqiu_hl_202109%22}; _gat=1; tt_scid=FKnWNWpxYy9KCFHAFfiQvg.GKlrVP.cvEbFNrAaHkFIiBhj6mizf8GFAWshV-m8f2a22'
        var str = cookieStr.split(';');
        console.log(str);
        for(let i = 0;i<str.length;i++){
            var str1 = str[i].split('=');

        }
        const parseCookie = str =>
            str 
               .split(';')
               .map(v => v.split('='))
               .reduce((acc,v) =>{
                   acc[v[0]] = v[1]
                   return acc
               } ,{})//把数组推平的方法

        console.log(parseCookie(cookieStr));
    </script>
</body>
</html>